<?php
$in_site = "dassnfu";
$page = "Activiteiten2";
$back_button = "Back";
$back_button_link = "/extra/agenda/nmr2/";
include_once($_SERVER['DOCUMENT_ROOT']."/start.php");
$style_nmr = 2;

$bestanden = "<script type='text/javascript'>
var aanwezigen_show = false;
$(document).ready(function() {
	$('#aanwezigen_trigger').click(function() {
		if(aanwezigen_show) {
			$('#aanwezigen').slideUp();
			aanwezigen_show = false;
		}else {
			$('#aanwezigen').slideDown();
			aanwezigen_show = true;
		}
	});
});
</script>";

$bestanden .= "<style type='text/css'>
.alternate {
	background-color: #F2F2F2;
}
table.table_list {
	margin: 10px 0px;
	padding: 0px;
	width: 100%;
	background: #ffffff;
	border-top: 2px solid #c2c2c2;
	border-bottom: 2px solid #c2c2c2;
}
table.table_list tr td.activiteiten_date {
	background-image: url('/images/style2/icons/ic_menu_clock.png');
	background-position: 5px center;
	background-repeat: no-repeat;
	background-size: 1.5em 1.5em;
	padding-left: 2em;
}
table.table_list tr td.ok_icon {
	background-image: url('/images/style2/icons/ic_menu_tick.png');
	background-position: 5px center;
	background-repeat: no-repeat;
	background-size: 1.5em 1.5em;
	padding-left: 2em;
}
table.table_list tr td.cancel_icon {
	background-image: url('/images/style2/icons/ic_menu_stop.png');
	background-position: 5px center;
	background-repeat: no-repeat;
	background-size: 1.5em 1.5em;
	padding-left: 2em;
}
table.table_list tr td {
	width: 50%;
	border-top: 1px solid #ffffff;
	border-bottom: 1px solid #d2d2d2;
	
	height: 40px;
	overflow: hidden;
	color: #666;
	line-height: 40px;
	text-decoration: none;
	/*white-space: nowrap;*/
	text-overflow: ellipsis;
}
table.table_list tr td.accent {
	font-weight: bold;
}
table.table_list tr td a {
	display: block;
	margin: 0px;
	padding: 0px;
	width: 100%;
	height: 40px;
	overflow: hidden;
	color: #666;
	line-height: 40px;
	text-decoration: none;
	/*white-space: nowrap;*/
	text-overflow: ellipsis;
}
table.table_list tr td.opmerking {
	background-image: url('/images/style2/icons/ic_menu_dialog.png');
	background-position: 5px center;
	background-repeat: no-repeat;
	background-size: 1.5em 1.5em;
	padding-left: 2em;
}


table.table_small_list tr td {
	padding: 0px 5px;
	height: 30px;
	overflow: hidden;
	color: #666;
	line-height: 30px;
	text-decoration: none;
	/*white-space: nowrap;*/
	text-overflow: ellipsis;
	
	border-top: 1px solid #ffffff;
	border-bottom: 1px solid #d2d2d2;
}

div.individual {
	display: block;
	padding: 0px;
	margin: 15px 0px;
	width: 100%;
	background: #ffffff;
	border: 1px solid #c2c2c2;
}
div.individual h4 {
	margin: 0px;
	padding: 0px;
	height: 30px;
	line-height: 30px;
	background: #e2e2e2;
	border-bottom: 1px solid #c2c2c2;
	text-align: center;
}
</style>";
include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/database_connectie.php");

include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/dag_maand.php");
include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/activiteiten_functies3.php");
include_once($_SERVER['DOCUMENT_ROOT']."/php_functions/instellingen.php");
include_once($_SERVER['DOCUMENT_ROOT']."/header.php");

if(empty($_GET['agendaId'])) {
	echo "<p class='error'>Er is geen activiteit geselecteerd</p>";
	include_once($_SERVER['DOCUMENT_ROOT']."/footer.php");
}

$alles_goed = true;

if($alles_goed == true) {
	//Activiteit zichtbaar maken
	$result = mysql_query("SELECT DISTINCT Agenda.agendaId, Agenda.*, Afmelden.reden, Wedstrijdinfo.bericht, Wedstrijdinfo.symbool,
			CASE WHEN (Afmelden.afmeldenId IS NOT NULL) THEN Afmelden.soort WHEN (Vakantie.vakantieId IS NOT NULL) THEN 4 ELSE NULL END AS afwezig
		FROM Teambeheer, Agenda
			LEFT JOIN Wedstrijdinfo ON Agenda.agendaId = Wedstrijdinfo.agendaId
			LEFT JOIN Afmelden ON Agenda.agendaId = Afmelden.agendaId AND Afmelden.spelerId = '".$spelerId."'
			LEFT JOIN Vakantie ON Vakantie.spelerId = '".$_SESSION['spelerId']."' AND Agenda.datum >= Vakantie.van AND Agenda.datum <= Vakantie.tot 
		WHERE 
		Agenda.agendaId = '".$_GET['agendaId']."'
			AND Teambeheer.spelerId = '".$spelerId."' AND Teambeheer.teamId = Agenda.teamId
			AND (((Teambeheer.teamfunctie > '0' OR Teambeheer.seizoenZichtbaar = '1') AND YEAR(Agenda.datum) = YEAR(Teambeheer.van))
				OR Agenda.datum >= Teambeheer.van)
			AND (Agenda.datum <= Teambeheer.tot OR Teambeheer.tot IS NULL)
		ORDER BY Agenda.datum");
	if($result <> null && mysql_num_rows($result) > 0) {
		/************ De tabel wordt aangemaakt **************/
		//echo "<h1>Activiteit</h1>";
		set_activiteiten_tabel($result, 0, null, null, null, true);
	}else {
		echo "<div class='error'><p class='icon'>Het ophalen van de activiteit is mislukt.</p></div>";
	}
	
	//Opvragen wie er als aanwezig staan bij de activiteit )als je dat recht hebt
	$aanwezig = -1;
	if($_SESSION['rechten'] & (1 << $rechten['afmeldingen_bekijken'])) {
		$result = mysql_query("SELECT Speler.spelerId, Speler.voornaam, Speler.tussenvoegsel, Speler.achternaam, Speler.bondsnummer FROM Speler, Agenda
						JOIN Teambeheer ON (Teambeheer.spelendLid = '1' AND Teambeheer.teamId = Agenda.teamId AND Teambeheer.van <= Agenda.datum AND (Teambeheer.tot >= Agenda.datum OR Teambeheer.tot IS NULL)) 
						LEFT JOIN Afmelden ON Afmelden.agendaId = Agenda.agendaId AND Afmelden.spelerId = Teambeheer.spelerId
						WHERE Agenda.agendaId = '".$_GET['agendaId']."'
							AND Teambeheer.spelendLid = '1' AND Teambeheer.van <= Agenda.datum AND (Teambeheer.tot >= Agenda.datum OR Teambeheer.tot IS NULL)
							AND Speler.spelerId = Teambeheer.spelerId
							AND ((Afmelden.agendaId > 0 AND Afmelden.spelerId = Teambeheer.spelerId
								AND ((Agenda.afmelden = '1' AND (Afmelden.afmeldenId IS NULL OR Afmelden.soort = '1'))
									OR (Agenda.afmelden = '2' AND Afmelden.soort = '1')))
								OR (Agenda.afmelden = '1' AND Afmelden.agendaId IS NULL))
						ORDER BY Speler.achternaam, Speler.voornaam, Speler.tussenvoegsel, Speler.spelerId");
		if($result <> null) {
			$aanwezigen = mysql_num_rows($result);
		}
	}
	
	if($aanwezigen >= 0) {
		echo "<div class='individual'>";
			echo "<h4>Aanwezigen (".$aanwezigen.")</h4>";
			
			echo "<table id='aanwezigen' class='table_small_list' style='width: 100%;' cellspacing='0'>";
				$color = false;
				while($row = mysql_fetch_array($result)) {
					echo "<tr".($color ? " class='alternate'" : "").">";
						echo "<td style='width: 79%;'>".$row['voornaam']." ".(isset($row['tussenvoegsel']) ? $row['tussenvoegsel']." " : "").$row['achternaam']."</td>";
						echo "<td style='width: 19%; font-style: italic; text-align: right;'>".(isset($row['bondsnummer']) ? "(".$row['bondsnummer'].")" : "")."</td>";
					echo "<tr>";
					$color ? $color = false : $color = true;
				}
			echo "</table>";
		echo "</div>";
	}
	
	// ZELF AF/AANMELDEN
	echo "<div class='individual' style='text-align: center;'>";
		echo "<h4>Af/aanmelden</h4>";
		echo "<textarea style='width: 98%; height: 60px; margin: 5px auto;'></textarea>";
	echo "</div>";
}
include_once($_SERVER['DOCUMENT_ROOT']."/footer.php");
?>
